package cn.bluemobi.app.controller.orders;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.bluemobi.app.core.controller.AppBaseController;
import cn.bluemobi.app.entity.form.CommentForm;
import cn.bluemobi.app.entity.form.OrderForm;
import cn.bluemobi.app.entity.output.Balance;
import cn.bluemobi.app.entity.output.Order;
import cn.bluemobi.app.entity.output.Pay;
import cn.bluemobi.app.service.OrderService;
import cn.bluemobi.common.core.dto.Dto;
import cn.bluemobi.common.core.dto.Page;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;

@Controller
@RequestMapping("/order")
@Api(description = "订单", value = "order")
public class OrderController extends AppBaseController {

	@Autowired
	private OrderService orderService;

	@RequestMapping("/balanceByCart")
	@ApiOperation(value = "购物车结算", httpMethod = "POST")
	@ResponseBody
	public Dto<Balance> balanceByCart(
			@ApiParam("会员ID") @RequestParam("memberId") String memberId,
			@ApiParam("购物车ID(多个已逗号隔开)") @RequestParam("shoppingCartIds") String shoppingCartIds) {
		return orderService.balanceByCart(memberId, shoppingCartIds);
	}

	@RequestMapping("balanceRightNow")
	@ApiOperation(value = "立即购买结算", httpMethod = "POST")
	@ResponseBody
	public Dto<Balance> balanceRightNow(
			@ApiParam("会员ID") @RequestParam("memberId") String memberId,
			@ApiParam("商品id") @RequestParam("commodityId") String commodityId,
			@ApiParam("规格id") @RequestParam("specificationId") String specificationId,
			@ApiParam("数量") @RequestParam("quantity") String quantity) {
		return orderService.balanceRightNow(memberId, commodityId,
				specificationId, quantity);
	}

	@RequestMapping("/sumbitOrder")
	@ApiOperation(value = "提交订单", httpMethod = "POST")
	@ResponseBody
	public Dto<Pay> sumbitOrder(
			@ApiParam("会员ID") @RequestParam("memberId") String memberId,
			@RequestBody OrderForm orderForm) {
		return orderService.submitOrder(memberId, orderForm);
	}

	@RequestMapping("/findMyOrders")
	@ApiOperation(value = "查询订单", httpMethod = "POST")
	@ResponseBody
	public Page<Order> findMyOrders(
			@ApiParam("页码") @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
			@ApiParam("每页显示条数") @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
			@ApiParam("会员ID") @RequestParam("memberId") String memberId,
			@ApiParam(value = "订单状态(0待支付，1待发货，2待收货，3待评价，4交易完成，5交易取消） ") @RequestParam(value = "orderStatus", required = false) String orderStatus) {
		return orderService.findMyOrders(pageNo, pageSize, memberId,
				orderStatus);
	}

	@RequestMapping("/findOrderDetail")
	@ApiOperation(value = "查询订单详情", httpMethod = "POST")
	@ResponseBody
	public Dto<Order> findOrderDetail(
			@ApiParam("会员ID") @RequestParam("memberId") String memberId,
			@ApiParam("订单ID") @RequestParam(value = "orderId") String orderId) {
		return orderService.findOrderDetail(memberId, orderId);
	}

	@RequestMapping("/cancelOrder")
	@ApiOperation(value = "取消订单", httpMethod = "POST")
	@ResponseBody
	public Dto<Object> cancelOrder(
			@ApiParam("会员ID") @RequestParam("memberId") String memberId,
			@ApiParam("订单ID") @RequestParam("orderId") String orderId) {
		return orderService.cancelOrder(memberId, orderId);
	}

	@RequestMapping("/deleteOrder")
	@ApiOperation(value = "删除订单", httpMethod = "POST")
	@ResponseBody
	public Dto<Object> deleteOrder(
			@ApiParam("会员ID") @RequestParam("memberId") String memberId,
			@ApiParam("订单id") @RequestParam("orderId") String orderId) {
		return orderService.deleteOrder(memberId, orderId);
	}

	@RequestMapping("/confirmReceipt")
	@ApiOperation(value = "确认收货", httpMethod = "POST")
	@ResponseBody
	public Dto<Object> confirmReceipt(
			@ApiParam("会员ID") @RequestParam("memberId") String memberId,
			@ApiParam("订单id") @RequestParam("orderId") String orderId) {
		return orderService.confirmReceipt(memberId, orderId);
	}

	// @RequestMapping("/applyAfterSales")
	// @ApiOperation(value = "申请售后", httpMethod = "POST")
	// @ResponseBody
	// public Dto<Object> applyAfterSales(
	// @ApiParam("会员ID") @RequestParam("memberId") String memberId,
	// @ApiParam("申请售后参数json") @RequestBody OrderReturnForm orderReturnForm) {
	// return orderService.applyAfterSales(memberId, orderReturnForm);
	// }

	// @RequestMapping("/findLogisticsDetail")
	// @ApiOperation(value = "查询物流详情", httpMethod = "POST")
	// @ResponseBody
	// public Dto<Logistics> findLogisticsDetail(
	// @ApiParam("会员ID") @RequestParam("memberId") String memberId,
	// @ApiParam("订单id") @RequestParam("orderId") Long orderId,
	// @ApiParam("物流公司编号") @RequestParam("logisticsCode") String logisticsCode,
	// @ApiParam("物流公司名称") @RequestParam("logisticsCompany") String
	// logisticsCompany,
	// @ApiParam("物流单号") @RequestParam(value = "logisticsNumber") String
	// logisticsNumber) {
	// return orderService.findLogisticsDetail(memberId, orderId,
	// logisticsCode, logisticsCompany, logisticsNumber);
	// }

	@RequestMapping("/commentProduct")
	@ApiOperation(value = "评价商品", httpMethod = "POST")
	@ResponseBody
	public Dto<Object> commentProduct(
			@ApiParam("会员ID") @RequestParam("memberId") String memberId,
			@RequestBody CommentForm commentForm) {
		return orderService.commentProduct(memberId, commentForm);
	}

	// @RequestMapping("/findMyAfterSaless")
	// @ApiOperation(value = "查询售后", httpMethod = "POST")
	// @ResponseBody
	// public Page<AfterSales> findMyAfterSaless(
	// @ApiParam("页码") @RequestParam(value = "pageNo", defaultValue = "1")
	// Integer pageNo,
	// @ApiParam("每页显示条数") @RequestParam(value = "pageSize", defaultValue =
	// "20") Integer pageSize,
	// @ApiParam("会员ID") @RequestParam("memberId") String memberId) {
	// return orderService.findMyAfterSaless(pageNo, pageSize, memberId);
	// }
	//
	// @RequestMapping("/findMyAfterSalesDetail")
	// @ApiOperation(value = "查询售后详情", httpMethod = "POST")
	// @ResponseBody
	// public Dto<AfterSales> findMyAfterSalesDetail(
	// @ApiParam("会员ID") @RequestParam("memberId") String memberId,
	// @ApiParam("售后ID") @RequestParam("afterSalesId") String afterSalesId) {
	// return orderService.findMyAfterSalesDetail(memberId, afterSalesId);
	// }

}
